package unrn.isiii.bean;

import java.util.ArrayList;
import java.util.List;

import javax.faces.component.UIComponent;
import javax.faces.component.UISelectItems;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import unrn.isiii.dao.TaskDao;
import unrn.isiii.model.Task;


@Component("convertProveedor")
public class ConvertProveedor implements Converter {

	@Autowired
	private TaskDao proveedorDao;

	public TaskDao getProveedorDao() {
		return proveedorDao;
	}

	public void setProveedorDao(TaskDao proveedorDao) {
		this.proveedorDao = proveedorDao;
	}

	public Object getAsObject(FacesContext facesContext, UIComponent component,
			String value) {
		if (value == null || value.equals("")) {
			return null;
		}

		return getProveedorDao().find(Long.parseLong(value));

	}

	@Override
	public String getAsString(FacesContext arg0, UIComponent arg1, Object value) {
		return value instanceof Task ? ((Task) value).getId()
				.toString() : "";
	}
}